<?xml version="1.0"?>
<xsl:stylesheet version="1.0" 
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:user="http://ionrock.org/ns/wsgiappclient/user"
                xmlns:app="http://www.w3.org/2007/app"
                xmlns:a="http://www.w3.org/2005/Atom"
                xmlns:ac="http://ionrock.org/ns/xsltemplate"
                xmlns:dyn="http://exslt.org/dynamic"
                xmlns:f="http://xmlns.4suite.org/ext" 
                xmlns:xh="http://www.w3.org/1999/xhtml"
                xmlns:ion="http://ionrock.org/ns/http-document"
                xmlns:exsl="http://exslt.org/common"
                xmlns:func="http://exslt.org/functions"
                xmlns="http://www.w3.org/1999/xhtml"
                extension-element-prefixes="dyn f ion func"
                exclude-result-prefixes="ac xh #default dyn f ion exsl a user app">

  <xsl:output method="html" omit-xml-declaration="yes" indent="yes" />
  <xsl:param name="ac:base_url" />
  <xsl:param name="ac:openid" />

  <xsl:param name="ac:service_base_url" />

  <xsl:param name="ac:service" />
  <xsl:param name="ac:username" />
  <xsl:param name="ac:password" />
  <xsl:param name="ac:xml_base" />
  <xsl:param name="ac:location" />
  <xsl:param name="ac:flash" />
  <xsl:param name="ac:form_action">.</xsl:param>
  <xsl:param name="ac:check_params">Nope not working</xsl:param>
  
  <xsl:template match="text()" />
  <xsl:template match="*" />

  <xsl:template match="/">
    <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
        <title>Atom Publishing Protocol Client</title>
        <xsl:variable name="css" select="f:resolve-url($ac:base_url, 'static/css/styles.css')" />
        <link rel="stylesheet" type="text/css" href="{$css}" />
        <script type="text/javascript" language="javascript" src="http://code.jquery.com/jquery-latest.js"><xsl:text> </xsl:text></script>
        
      </head>
      <body>
        <div id="content-block">
          <div id="header-block">
            <h4>WSGIAppClient</h4>
            <div class="subheading">An Atom Publishing Protocol Client</div>
            <div class="breadcrumbs">
              <a href="{ac:this-base-url()}">home</a> &#8594;
              service
            </div>
          </div>
          <div id="body-block">
            <xsl:if test="$ac:flash">
              <div class="flash-message">
                <xsl:value-of select="$ac:flash" />
              </div>
            </xsl:if>
            <xsl:apply-templates select="/app:service/app:workspace" />
            <div class="add-service-forms">
              <form action="{ac:this-base-url('service')}" method="POST">
                <fieldset>
                  <legend>Add Service</legend>
                  <input type="hidden" name="action" value="service-get-collections" />
                  <div class="text-input">
                    <label class="text" for="app_service">Service URL</label>
                    <input type="text" name="app_service" value="{$ac:service}" />
                  </div>
                  <div class="text-input">
                    <label class="text" for="username">Username</label>
                    <input type="text" name="username" value="{$ac:username}" />
                  </div>
                  <div class="text-input">
                    <label class="text" for="password">Password</label>
                    <input type="password" name="password" value="{$ac:password}" />
                  </div>
                  <input type="submit" name="submit" value="add" />
                </fieldset>
              </form>
            </div>
            <div>
              <xsl:copy-of select="." />
            </div>
          </div>
        </div>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="app:workspace">
    <form action="{ac:this-base-url('service')}" method="post">
      <input type="hidden" name="action" value="user-add-collections" />
      <fieldset>
        <legend><xsl:value-of select="./a:title" /></legend>
        <xsl:apply-templates />
        <br/> 
        <input type="submit" name="submit" value="add collections" />
      </fieldset>
    </form>
  </xsl:template>

  <xsl:template match="app:collection">
    <xsl:for-each select=".">
      <xsl:variable name="url" 
                    select="f:resolve-url($ac:service_base_url, ./@href)" />
      <xsl:variable name="title" select="./a:title" />
      <div>
        <input type="checkbox" name="collection_urls" value="{$url}" />
        <xsl:value-of select="$title" />
      </div>
    </xsl:for-each>
  </xsl:template>

  <func:function name="ac:this-base-url">
    <xsl:param name="path" />
    <func:result select="f:resolve-url($ac:base_url, $path)" />
  </func:function>

</xsl:stylesheet>